﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class StockHistory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!HttpContext.Current.Request.IsAuthenticated)
        {
            Response.Redirect("~/login.aspx");
        }
        else
        {
            if ((string)Session["GameID"] == "-1")
                Response.Redirect("~/GameMode.aspx");

            else
            {

                if (ViewState["startdate"] == null)
                {
                    if (Request.Form["txtStartDate"] != null)
                        ViewState["startdate"] = Request.Form["txtStartDate"].ToString();

                    else
                        ViewState["startdate"] = "";

                    if ((string)ViewState["startdate"] != "")
                    {
                        var script = "$('#txtStartDate').val('" + (string)ViewState["startdate"] + "');";
                        ClientScript.RegisterStartupScript(typeof(string), "text", script, true);

                    }
                }

                else if (ViewState["startdate"] != null)
                {
                    if (Request.Form["txtStartDate"] != null)
                        ViewState["startdate"] = Request.Form["txtStartDate"].ToString();

                    if ((string)ViewState["startdate"] != "")
                    {
                        var script = "$('#txtStartDate').val('" + (string)ViewState["startdate"] + "');";
                        ClientScript.RegisterStartupScript(typeof(string), "text", script, true);

                    }
                }

                if (ViewState["enddate"] == null)
                {
                    if (Request.Form["txtEndDate"] != null)
                    {
                        ViewState["enddate"] = Request.Form["txtEndDate"].ToString();
                    }

                    else
                        ViewState["enddate"] = "";

                    if ((string)ViewState["enddate"] != "")
                    {
                        var script = "$('#txtEndDate').val('" + (string)ViewState["enddate"] + "');";
                        ClientScript.RegisterStartupScript(typeof(string), "text1", script, true);

                    }
                }

                else if (ViewState["enddate"] != null)
                {
                    if (Request.Form["txtEndDate"] != null)
                    {
                        ViewState["enddate"] = Request.Form["txtEndDate"].ToString();
                    }

                    if ((string)ViewState["enddate"] != "")
                    {
                        var script = "$('#txtEndDate').val('" + (string)ViewState["enddate"] + "');";
                        ClientScript.RegisterStartupScript(typeof(string), "text1", script, true);

                    }
                }
            }
        }
    }
    protected void DropDownListComName_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownListComName.SelectedIndex != 0)
        {
            if (RadioButtonListType.SelectedValue.Equals("Text Based"))
            {
                GridViewStockDetails.DataSourceID = "SqlDataSourceStockDetails";
                GridViewStockDetails.DataBind();
            }
            else
            {
                GridViewStockDetails.Controls.Clear();
                GridViewStockDetails.DataSourceID = "";
                GridViewStockDetails.DataBind();

                if (!ClientScript.IsStartupScriptRegistered("graph"))
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "graph", "drawGraph();", true);
                }
            }
        }
    }

    protected void RadioButtonListType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (RadioButtonListType.SelectedValue.Equals("Text Based"))
        {
            GridViewStockDetails.DataSourceID = "SqlDataSourceStockDetails";
            GridViewStockDetails.DataBind();
            zoom_label.Visible = false;
        }

        else if (RadioButtonListType.SelectedValue.Equals("Graph"))
        {
            GridViewStockDetails.Controls.Clear();
            GridViewStockDetails.DataSourceID = "";
            GridViewStockDetails.DataBind();
            zoom_label.Visible = true;

            if (!ClientScript.IsStartupScriptRegistered("graph"))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "graph", "drawGraph();", true);
            }
        }
        else if (RadioButtonListType.SelectedValue.Equals("Compare"))
        {
            Response.Redirect("Compare Stock.aspx");
        
        }

    }
}